<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>随机生成指定长度的字符串</title>
</head>
<body>
  <button onclick="randomString(3)">生成随机3位字符串</button>
  <p id="output"></p>

  <script>
    
    function randomString(length) {
      let result = '';
      let characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
      for (let i = 0; i < length; i++) {
        result += characters.charAt(Math.floor(Math.random() * characters.length));
      }
      document.getElementById('output').innerText = "随机生成的" + length + "位字符串为：" + result;
    }
  </script>
</body>
</html>2020